package editors.gui;
import graphics.system.Color;
import graphics.system.GLTools;
import tools.Floatmath;
import tools.Point;
public class Rect {
	private Point center;
	private float width;
	private float height;
	public Rect() {
		this.center = new Point(0, 0);
		width = 0;
		height = 0;
	}
	public Rect(Point center, float width, float height) {
		this.center = center;
		this.width = width;
		this.height = height;
	}
	public void setCenter(Point center) {
		this.center = center;
	}
	public boolean isIn(Point p) {
		float xmin = center.x - width / 2;
		float xmax = center.x + width / 2;
		float ymin = center.y - height / 2;
		float ymax = center.y + height / 2;
		if (xmin <= p.x && p.x <= xmax && ymin <= p.y && p.y <= ymax)
			return true;
		return false;
	}
	public void draw(Color c) {
		GLTools.drawRect(center, width, height, 0, c);
		/*
		 * GLTools.drawPoint(getTopLeft(), Color.red, 5); GLTools.drawPoint(getBottomRight(), Color.green, 5); GLTools.drawPoint(center, Color.white, 5);
		 */
	}
	public Point getTopLeft() {
		return new Point(center.add(new Point(-width / 2.0f, height / 2.0f)));
	}
	public Point getBottomRight() {
		return new Point(center.add(new Point(width / 2.0f, -height / 2.0f)));
	}
	public Point getCenter() {
		return center;
	}
	public void setWidth(float w) {
		this.width = w;
	}
	public void setHeight(float h) {
		this.height = h;
	}
	public float getWidth() {
		return width;
	}
	public float getHeight() {
		return height;
	}
	public void move(Point dx) {
		center.sAdd(dx);
	}
}
